package user

import (
	"context"
	"github.com/jinzhu/copier"
	"go.uber.org/zap"
	"navi-mumbai/app/rpc/usercenter/pb"

	"navi-mumbai/app/api/business/internal/svc"
	"navi-mumbai/app/api/business/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetAppInitDataLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetAppInitDataLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetAppInitDataLogic {
	return &GetAppInitDataLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetAppInitDataLogic) GetAppInitData(req *types.GetAppInitDataReq) (resp *types.GetAppInitDataResp, err error) {

	var in pb.GetAppInitDataReq = pb.GetAppInitDataReq{
		AppVer:      req.AppVer,
		UserChannel: req.UserChannel,
		Device:      req.Device,
		DeviceId:    req.DeviceId,
	}
	var rsp *pb.GetAppInitDataResp
	rsp, err = l.svcCtx.UcUserRpc.GetAppInitData(l.ctx, &in)
	if err != nil {
		l.Logger.Errorf("err == ", zap.Error(err))
		return nil, err
	}
	resp = &types.GetAppInitDataResp{
		AppConfig:       &types.AppConfig{},
		BannerConfig:    &types.BannerConfig{List: make([]*types.BannerData, 0)},
		ApkUpdateConfig: &types.ApkUpdateConfig{},
	}
	_ = copier.Copy(resp, rsp)
	return
}
